<!DOCTYPE html>
<html>
<head>
   <meta charset="utf-8">
	<title>动态表格布局</title>
</head>
<body>

  <?php  
   $array=[
     ['id'=>1,'name'=>'zhangxing','age'=>24 ,'zhiwei'=>'texter','salay'=>'50000'],
     ['id'=>2,'name'=>'wangjuyang','age'=>26 ,'zhiwei'=>'chesi','salay'=>'70000'],
     ['id'=>3,'name'=>'huancaifu','age'=>35 ,'zhiwei'=>'texter2','salay'=>'60000'],
     ['id'=>4,'name'=>'lixingfen','age'=>23 ,'zhiwei'=>'chesi3','salay'=>'40000'],
     ['id'=>5,'name'=>'zhuzexin','age'=>27 ,'zhiwei'=>'CEO5','salay'=>'30000']
   ];
   $getdate=$array;
   if ($_SERVER['REQUEST_METHOD']==='POST') {
     $select=[];
     $selectkey=isset($_POST['zhiweikey'])?trim(htmlspecialchars($_POST['zhiweikey'])):'';
     //$selectkey=htmlspecialchars(string);//过滤特殊数据
    foreach ($array as $value) {
    	if (stripos($value['zhiwei'], $selectkey)===0) {
    		$select[]=$value;
          	//print_r($select);
    	}elseif ($selectkey==='') {
    		$select[]=$value;
    	}
    }
    $getdate=$select;

    }

   if (isset($_GET['s'])&&$_GET['s']=='age') {
   	usort($array, 'compareByAge');
   }

   function compareByAge($emp1,$emp2)
   {

   	return ($emp1['age']-$emp2['age']);
   }
  ?>
  <a href="?s=age">点击按年龄进行排序</a>
  <form method="post">
    <div>
        <input type="text" name="zhiweikey"/>
        <input type="submit" value="查询">
    </div>
  </form>
  <table>
     <tr>
       <th>id</th>
       <th>name</th>
       <th>age</th>
       <th>zhiwei</th>
       <th>salay</th>
       <th>action</th>
     </tr>
     
     <?php  foreach ($getdate as $value): ?>
     	<tr>
      <td><?php echo $value['id']?></td>
      <td><?php echo $value['name']?></td>
      <td><?php echo $value['age']?></td>
      <td><?php echo $value['zhiwei']?></td>
      <td><?php echo $value['salay']?></td>
      <td><a href="tableaction.php?id=<?=$value['id'] ?>&name=<?=$value['name']?>&age=<?=$value['age']?>&zhiwei=<?=$value['zhiwei']?>">跳转</td>
      </tr>
    <?php endforeach; ?>
    
  </table>
</body>
</html>